import 'package:app_settings/app_settings.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:zhrs/pages/signatures.dart';
showSnackBar(BuildContext context, String message,
    {Duration duration = const Duration(milliseconds: 1200)}) {
  Scaffold.of(context).showSnackBar(SnackBar(
    duration: duration,
    content: Text(message),
    action: SnackBarAction(
      label: "OK",
      onPressed: () {
        //Navigator.of(context).pop();
      },
    ),
  ));
}
alertDialog(BuildContext context,String msg){
  showDialog<Null>(
    context: context,
    barrierDismissible: false,
    child: new AlertDialog(
      title: new Text(
        '温馨提示',
        style: new TextStyle(
          color: Colors.black54,
          fontSize: 18.0,
        ),
      ),
      content: new Text(msg),
      actions: <Widget>[
        new FlatButton(
            onPressed: () {
              Navigator.pop(context);
            },
            child: new Text('确定')),
      ],
    ),
  );
}

 Future<String>  alertSignature(BuildContext context) async{

  String res;
 await showDialog(

    context: context,
    barrierDismissible: false,
    builder: (ctx){
      return Sigmatures();
    },
    //actions,

  ).then((val){
    res=val.toString();
   print("result: \n"+val.toString());

 });
  return res;
}

  Future confirmDialog(BuildContext context,String msg) async{
  return showDialog<bool>(
    context: context,
    barrierDismissible: false,
    child: new AlertDialog(
      title: new Text(
        '温馨提示',
        style: new TextStyle(
          color: Colors.black54,
          fontSize: 18.0,
        ),
      ),
      content: new Text(msg),
      actions: <Widget>[
        new FlatButton(
            onPressed: ()  {
             AppSettings.openAppSettings().then((va){
               return true;
             });
            },
            child: new Text('确定')),
        new FlatButton(
            onPressed: () {
              print("进入了");
              Navigator.pop(context);
            },
            child: new Text('取消')),
      ],
    ),
  );
}
Future<bool> onWillPop(BuildContext context) {
  return showDialog(
    context: context,
    builder: (context) => new AlertDialog(
      content: new Text('确定要退出APP吗？'),
      actions: <Widget>[
        new FlatButton(
          onPressed: () => Navigator.of(context).pop(false),
          child: new Text('否'),
        ),
        new FlatButton(
          onPressed: ()async {
            await SystemChannels.platform.invokeMethod('SystemNavigator.pop');
          },
          child: new Text('是'),
        ),
      ],
    ),
  ) ?? false;
}